<?php
namespace app\admin\service\account;

use app\admin\model\account\AccountsInfoModel;
use app\admin\service\BaseService;

/**
 * 行为日志-控制器
 * @author tangsan
 * Class Actionlog
 * @package app\admin\controller
 */
class AccountsInfoService extends BaseService
{
    /**
     * 构造函数
     * @author tangsan
     */
    public function __construct()
    {
        $this->model = new AccountsInfoModel();
    }

    /**
     * 获取数据列表
     * @return array
     * @author tangsan
     */
    public function getList()
    {
        $param = request()->param();

        // 查询条件
        $map = [];

        // 游戏名
        $jackpotName = getter($param, "JackpotName");
        if ($jackpotName) {
            $map[] = ["JackpotName", '=', $jackpotName];
        }
        // 玩家类型
        $isAndroid = getter($param, "IsAndroid");
        if (is_numeric($isAndroid)) {
            $map[] = ["IsAndroid", '=', $isAndroid];
        }
        // 玩家ID
        $userID = getter($param, "UserID");
        if ($userID) {
            $map[] = ["UserID", '=', $userID];
        }
        // 开始时间
        $start = getter($param, "start_LastLogonDate");
        if ($start) {
            $map[] = ["LastLogonDate", '>=', $start];
        }
        // 结束时间
        $end = getter($param, "end_LastLogonDate");
        if ($end) {
            $map[] = ["LastLogonDate", '<=', $end];
        }
        $list = $this->model->alias('a')->with(['recordUserWinJackpot' => function($query) {
            $query->field('WinScore,UserID');
        }])
            ->where($map)
//            ->order('thinkphp.pid ASC,thinkphp.sort ASC')
            ->field('a.UserID,a.LastLogonDate')
            ->page(PAGE, PERPAGE)
            ->select()->toArray();

        //获取数据总数
        $count = $this->model->where($map)->count();

        //返回结果
        $message = array(
            "msg" => '操作成功',
            "code" => 0,
            "data" => $list,
            "count" => $count,
        );
        return $message;
    }
}